using System;
using System.Web.Mvc;
using Wikey.Domain.Components;
using Wikey.Domain.Repository;

namespace Wikey.Web.Mvc.Controllers
{
    public class DocumentController : Controller
    {
        //
        // GET: /Document/
        private readonly IDocumentRepository repository;
        public DocumentController()
        {
            repository = Factory.Get<IDocumentRepository>();
        }
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Get( string id )
        {
            var document = repository.FindByFileName(id);
            var absoluteFilePath = Server.MapPath(
                String.Format("~/Uploads/{0}", document.Filename)
                );
            return File(absoluteFilePath, document.ContentType, id);
        }
    }
}
